import i18n from 'i18next'
import enLang from './langs/en'
import zhLang from './langs/zh'
import twLang from './langs/tw'
import { initReactI18next } from 'react-i18next'

let localLang = localStorage.getItem('language')
const browserLang = navigator.language
if (!localLang) {
  localLang = browserLang === 'zh-CN' ? 'zh' : 'en'
}

i18n.use(initReactI18next).init({
  resources: {
    en: { translation: enLang },
    zh: { translation: zhLang },
    tw: { translation: twLang }
  },
  lng: localLang,
  fallbackLng: 'zh',
  debug: false,
  interpolation: {
    escapeValue: false
  }
})

export default i18n
